home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 4.6 KB | 169 lines | [TEXT/ToyS] |
- property kasWinDims : {256, 128}
- property kasHtHead1 : {"<HTML>", "<HEAD>", "<TITLE>"}
- property kasHtHead2 : {"</TITLE>", "</HEAD>", "<BODY bgColor=white>"}
- property kasHtTail : {"</BODY>", "</HTML>"}
- property kasTblHead : {"<TABLE BORDER=4 CELLPADDING=4 CELLSPACING=2>"}
- property kasRowHead : {"<TR>", "<TD>"} -- Img tag goes after this
- property kasRowDiv : {"</TD>", "<TD VALIGN=top>"} -- Name/Link goes after this
- property kasRowTail : {"</A>", "</TD>", "</TR>"}
- property kasTblTail : {"</TABLE>"}
-
- property kasImgTag : "<IMG"
- property kasImgH : "HEIGHT"
- property kasImgW : "WIDTH"
- property kasImgSrc : "SRC"
-
- property kasHRefTag : "<A"
- property kasHRefSrc : "HREF"
-
- property kasExportFormat : "JPEG" -- QT Supports JPEG, BMP or QTIF but not GIF
- property kasExtension : ".jpg"
-
- global gasDrawWin
-
-
- on run
- open {"◊MAXI◊:Desktop Folder:Thrash"}
- end run
-
-
- on open fsObjs
- -- Initialize
- set winBox to {0, 0} & kasWinDims
- set icnBox to {0, 16} & kasWinDims
- set txtBox to {0, 0, item 1 of kasWinDims, 16}
-
- if true then -- Runtime?
- -- Display window
- set gasDrawWin to ¬
- display drawing titled ¬
- "Folder to HTML" with dimensions kasWinDims
- -- Black background
- draw a box into gasDrawWin ¬
- inside of winBox ¬
- filling it with the pen
- end if
-
- repeat while fsObjs is not {}
- -- Pop #1 off list
- set fsObj to item 1 of fsObjs
- set fsObjs to edit list fsObjs with edits {-1}
-
- -- Only do folders!
- set fsInf to extended info for fsObj
- if (catalog kind of fsInf is not a folder) then
- display dialog "Only Folders!" default button 1 with icon stop
- return
- end if
-
- -- Create output folder
- set fsPath to (fsObj as string)
- set fsName to catalog name of fsInf
- set fsDad to (parent spec of fsInf) as string
- set outPath to fsName & ".img"
- set outFold to («event ÅkuFƒNew» fsDad given «class NAME»:outPath) as string
- set outPath to catalog name of (basic info for outFold) -- Update in case name changed when creating
-
- -- Start html page and table
- set html to kasHtHead1 & ("Folder " & fsName) & kasHtHead2 & kasTblHead
-
- -- List folder
- set dirFiles to the entries in fsObj
-
- -- Get icons
- repeat with dirFile in dirFiles
- -- Break it down
- set itemPath to fsPath & dirFile
- set isFold to (catalog kind of (basic info for itemPath) is a folder)
-
- -- Create sub folder html?
- if (isFold) then set fsObjs to fsObjs & {itemPath & ":"}
-
- -- Convert to picture, get bounds
- set ciPic to (the icon for itemPath) as picture
- set ciBox to picture bounds of (the picture info for ciPic)
- set ciDrawBox to CenterBox(ciBox, icnBox)
-
- -- Add row to table
- set html to html & kasRowHead
-
- -- Add Image
- set ciW to compile tag val {kasImgW, (item 3 of ciBox) - (item 1 of ciBox)}
- set ciH to compile tag val {kasImgH, (item 4 of ciBox) - (item 1 of ciBox)}
- set ciS to compile tag val {kasImgSrc, outPath & "/" & dirFile & kasExtension}
- set imgTag to compile tag {kasImgTag, ciW, ciH, ciS}
- set html to html & imgTag & kasRowDiv
-
- -- Add file/folder link to table
- if (isFold) then
- set href to compile tag val {kasHRefSrc, fsName & "/" & dirFile & ".html"}
- else
- set href to compile tag val {kasHRefSrc, fsName & "/" & dirFile}
- end if
- set ciTag to compile tag {kasHRefTag, href}
- set html to html & ciTag & dirFile
-
- -- End table row
- set html to html & kasRowTail
-
- -- Erase background
- draw a box into gasDrawWin ¬
- inside of winBox ¬
- filling it with the pen ¬
- without recording
-
- -- Show name
- draw a text box into gasDrawWin ¬
- inside of txtBox ¬
- using data dirFile ¬
- using state {text mode:2} ¬
- without recording
-
- -- Draw Icon
- draw a picture into gasDrawWin ¬
- inside of ciDrawBox ¬
- using data ciPic ¬
- without recording
-
- -- Save file
- store image ciPic ¬
- in (outFold & dirFile & kasExtension) ¬
- given «class îKnd»:kasExportFormat
- end repeat
-
- set html to html & kasTblTail & kasHtTail
- set htTxt to compile ML html
-
- -- Write html to file
- set fRef to ¬
- open fork from fsDad ¬
- named (fsName & ".html") ¬
- of type "TEXT" of creator "R*ch" with write access
- write data to fRef from buffer htTxt
- close fork fRef
- end repeat
- end open
-
-
- on quit
- display drawing gasDrawWin with disposal
- return (continue quit)
- end quit
-
-
- on CenterBox(src, dst)
- -- Place src in dst w/o scaling
- set dX to (item 1 of dst)
- set dY to (item 2 of dst)
- set sW to (item 3 of src) - (item 1 of src)
- set sH to (item 4 of src) - (item 2 of src)
- set dW to (item 3 of dst) - dX
- set dH to (item 4 of dst) - dY
-
- set bW to dX + (dW - sW) / 2
- set bH to dY + (dH - sH) / 2
-
- -- Center it
- return {bW, bH, bW + sW, bH + sH}
- end CenterBox
-